<!DOCTYPE html>
<html lang="zh_CN" xmlns:th="http://www.thymeleaf.org">
<head>
    <!--公用头部-->
    <th:block th:replace="common/head::commonHead('角色-小邑')" />
    <style>
        #formAdvForm .layui-row {
            margin-top: 20px;
        }
        #formAdvForm .layui-form-item {
            margin-bottom: 0;
        }
        #formAdvForm .layui-form-item .layui-inline {
            margin-bottom: 25px;
            margin-right: 0;
        }
    </style>
</head>
<!--公用js-->
<th:block th:replace="common/head::commonJs"/>
<script>
    var type = null;
    var url = null;
    var id = null;
    $(function () {
        id = utils.request.getQueryString("id");
        type = utils.request.getQueryString("type");
        if (type == 2) {
            url = basePath + '/role/editRole';
        } else {
            url = basePath + '/role/addRole';
        }
    })
</script>
<body marginwidth="0" marginheight="0">
<form class="layui-form" action="" id="formAdvForm" lay-filter="formAdvForm">
<div class="layui-fluid  layui-fluid-btn">
    <div class="layui-col-md12">
        <div class="layui-card"  style="margin: 10px;">
            <div class="layui-card-body">
                    <input name="id" type="text" style="display: none">
                <div class="layui-form-item layui-row">
                    <div class="layui-inline layui-col-md6">
                        <label class="layui-form-label layui-form-required">角色编码</label>
                        <div class="layui-input-block">
                            <input type="text" name="roleCode" id="roleCode" lay-verify="required" placeholder="请输入角色编码" autocomplete="off" class="layui-input">
                        </div>
                        </div>
                    <div class="layui-inline layui-col-md6">
                        <label class="layui-form-label layui-form-required">角色名</label>
                        <div class="layui-input-block">
                            <input type="text" name="roleName" id="roleName" lay-verify="required" placeholder="请输入角色名" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                    <div class="layui-form-item">
                        <div class="layui-inline layui-col-md6">
                        <label class="layui-form-label layui-form-required">排序</label>
                        <div class="layui-input-block">
                            <input type="number" name="sort" id="sort" lay-verify="required|numberInt" min="1"
                                   placeholder="请输入排序号" autocomplete="off" class="layui-input">
                        </div>
                        </div>
                        <div class="layui-inline layui-col-md6">
                        <label class="layui-form-label ">备注</label>
                        <div class="layui-input-block">
                            <input type="text" name="remark" id="remark" placeholder="请输入备注" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                    <div class="form-group-bottom">
                        <button class="xy-btn xy-btn-primary subCheckBtn" lay-submit lay-filter="formBtn">提交</button>
                        <button type="reset" class="xy-btn ">重置</button>
                    </div>
            </div>
        </div>
</div>
</div>
</form>
<script>
    layui.use(['layer', 'jquery', 'form', 'notice', 'numberInput'], function () {
        var $ = layui.jquery
            , form = layui.form
            , notice = layui.notice
            , numberInput = layui.numberInput
            , layer = layui.layer;

        //监听提交
        form.on('submit(formBtn)', function (data) {
            var formDate = data.field;
            if (type == 2) {
                if (isEmpty(formDate.id)) {
                    formDate.id = id;
                }
            }
            var loadIndex = null;
            checkSubBtn(1);
            sendAjaxPostToCallback(
                url,
                data.field,
                function (result){
                    if (result.success){
                        // 提示信息
                        top.layui.notice.msg(result.msg ,{icon: 1,position:"topCenter"});
                        // 获取当前iframe层的索引
                        var index = parent.layer.getFrameIndex(window.name);
                        // 关闭弹窗
                        parent.layer.close(index);
                        // 重载表格
                        parent.layui.table.reload('roleTable',{});
                    }else{
                        checkSubBtn(2);
                        top.layui.notice.msg(result.msg ,{icon: 2,position:"topCenter"});
                    }
                },
                function (data) {
                    checkSubBtn(2);
                    if (utils.string.isEmpty(data) && utils.string.isEmpty(data.msg)){
                        top.layui.notice.msg(data.msg ,{icon: 2,position:"topCenter"});
                    }else{
                        top.layui.notice.msg("服务器内部错误，请联系管理员~", {icon: 2,position:"topCenter"});
                    }
                },
                function (){
                    loadIndex = layer.load(1);
                },
                function (){
                    layer.close(loadIndex);
                },
            )
            return false;
        });
        /*修改回填表单*/
        if (type == 2){
            //获取详情信息，填充表单
            var loadIndex = null;
            sendAjaxPostToCallbackAsync(
                basePath + '/role/detailRole',
                {id: id},
                false,
                function (result) {
                    if (result.success == true) {
                        layui.form.val('formAdvForm', result.data);
                        numberInput.render("#sort", {
                            min: 1,
                            defaultValue:result.data.sort
                        });
                    } else {
                        top.layui.notice.msg(result.msg ,{icon: 2,position:"topCenter"});
                    }
                },
                function (e) {
                    top.layui.notice.msg("服务器内部错误，请联系管理员~", {icon: 2,position:"topCenter"});
                },
                function () {
                    loadIndex = layer.load(1);
                },
                function () {
                    layer.close(loadIndex);
                },
            )
        }else {
            numberInput.render("#sort", {
                min: 1,
                defaultValue:1
            });
        }
    });
</script>
</body>
</html>
